package aishua.com.mytestapplist.diyiview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;

import java.util.HashMap;
import java.util.HashSet;

import aishua.com.mytestapplist.R;
import aishua.com.mytestapplist.utils.LogUtils;

/**
 * Created by aishua on 2017/3/31.
 */

public class Myview extends Button {

    private static final String TAG = "myview-";
    private Paint mPaint;
    public Myview(Context context) {
        super(context);
    }

    public Myview(Context context, AttributeSet attrs) {
        super(context, attrs);
        LogUtils.v(TAG + "Myview()");
//        init();
//     测试git账号更改
        HashMap hashMap = new HashMap();
        HashSet hashSet = new HashSet();
    }

    public Myview(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }
    private void init(){
        mPaint = new Paint();
        mPaint.setAntiAlias(true);          //抗锯齿
        mPaint.setColor(getResources().getColor(R.color.yellow));//画笔颜色
        mPaint.setStyle(Paint.Style.FILL);  //画笔风格
        mPaint.setTextSize(36);             //绘制文字大小，单位px
        mPaint.setStrokeWidth(5);


        //画笔粗细
    }
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        LogUtils.v(TAG + "onMeasure()");
        LogUtils.v(TAG + "widthMeasureSpec-->" + widthMeasureSpec + ",heightMeasureSpec--->" + heightMeasureSpec);
        int mode_w = MeasureSpec.getMode(widthMeasureSpec);
        int size_w = MeasureSpec.getSize(widthMeasureSpec);
        int mode_h = MeasureSpec.getMode(heightMeasureSpec);
        int size_h = MeasureSpec.getSize(heightMeasureSpec);
        LogUtils.v(TAG + "size_w-->" + size_w + ",size_h--->" + size_h);
        setMeasuredDimension(400, 150);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        LogUtils.v(TAG + "onLayout()");
        LogUtils.v(TAG + "changed-->" + changed + ",left--->" + left + ",top-->" + top + ",right-->" + right + ",bottom--->" + bottom);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        canvas.drawColor(getResources().getColor(R.color.blank));   //设置画布背景颜色
//        canvas.drawCircle(50, 50, 50, mPaint);           //画实心圆

    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        LogUtils.v(TAG + "onFinishInflate()");
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        int e = event.getAction();
        switch (e) {
            case MotionEvent.ACTION_DOWN:
                LogUtils.v(TAG + "onTouchEvent()--MotionEvent.ACTION_DOWN");
//                return  false;
                break;
            case MotionEvent.ACTION_MOVE:
                LogUtils.v(TAG + "onTouchEvent()--MotionEvent.ACTION_MOVE");
//                return false;
                break;
            case MotionEvent.ACTION_UP:
                LogUtils.v(TAG + "onTouchEvent()--MotionEvent.ACTION_UP");
                break;
//                return true;
        }
        return super.onTouchEvent(event);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {

        int e = event.getAction();
        switch (e) {
            case MotionEvent.ACTION_DOWN:
                LogUtils.v(TAG + "dispatchTouchEvent()--MotionEvent.ACTION_DOWN");
//                return  true;
                break;
//                return  false;
            case MotionEvent.ACTION_MOVE:
                LogUtils.v(TAG + "dispatchTouchEvent()--MotionEvent.ACTION_MOVE");
//                return  false;
                break;
            case MotionEvent.ACTION_UP:
                LogUtils.v(TAG + "dispatchTouchEvent()--MotionEvent.ACTION_UP");
//                 return true;
                break;
        }
        return super.dispatchTouchEvent(event);
//        return true;
    }

}
